<%-- 
    Document   : SearchContent
    Created on : Oct 21, 2011, 10:53:11 PM
    Author     : linh
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="MODEL.POJO.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<%
    LoaiDanhMucPOJO loaidm = (LoaiDanhMucPOJO) request.getAttribute("LoaiDM");
    DanhMucPOJO danhm = (DanhMucPOJO) request.getAttribute("DM");
    SanPhamPOJO sanp = (SanPhamPOJO) request.getAttribute("TenSanPham");
    String loaisanpham = (String) request.getAttribute("LoaiSanPhams");
    int soluongtrang = (Integer) request.getAttribute("SoTrang");
%>

<div class="tieude">Ket qua tim kiem voi tu khoa:<%=(String) request.getAttribute("TuKhoa")%></div>
<% String error = (String) request.getAttribute("Error");
    if (error == null) {%>
<div class="noidung">
    <%
        ArrayList<ChiTietSanPhamPOJO> dsctsp = (ArrayList<ChiTietSanPhamPOJO>) request.getAttribute("DanhSachCTSPs");
        for (int j = 0; j < dsctsp.size(); j++) {
            ChiTietSanPhamPOJO ctsp = dsctsp.get(j);
    %>
    <div class="boxsp">
        <div class="name"><%=ctsp.getTensanpham()%></div>
        <div class="hinh"><a href="ChiTietController?Action=<%=loaisanpham%>&idchitietsanpham=<%=ctsp.getIdchitietsanpham()%>"><img src="<%=ctsp.getHinh()%>" /></a></div>
        <div class="mota"><%=ctsp.getMota()%></div>
        <div class="gia"><%=ctsp.getGiaban()%> vnd</div>
    </div>
    <% }%>
</div>
<%  int trangtruoc = 1;
    if (request.getParameter("Trang") != null) {
        int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
        if (tranghienhanh > 1) {
            trangtruoc = tranghienhanh - 1;
        }
    }
    String tukhoa = (String) request.getAttribute("TuKhoa");
    if (tukhoa != null) {%>
<a  href="SearchController?Action=Search&idloaisanpham=<%=loaisanpham%>&Trang=<%=trangtruoc%>&tbtensanpham=<%=tukhoa%>">[Trang trước]</a>Trang: 
<%  for (int i = 1; i <= soluongtrang; i++) {%>
<a href="SearchController?Action=Search&idloaisanpham=<%=loaisanpham%>&Trang=<%=i%>&tbtensanpham=<%=tukhoa%>"><%=i%><a/>
    <% }
        int trangsau = trangtruoc + 1;
        if (request.getParameter("Trang") != null) {
            int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
            if (trangsau < soluongtrang) {
                trangsau = tranghienhanh + 1;
            }
        }%>
    <a  href="SearchController?Action=Search&idloaisanpham=<%=loaisanpham%>&Trang=<%=trangsau%>&tbtensanpham=<%=tukhoa%>">[Trang sau]</a>
    <%}
    %>
    <% } else {%>
    <div class="noidung"><%=error%></div>
    <%}%>